import { reqDetailInfo, reqAddOrUpdateShopCart } from '@/api';
import { getUUID } from '@/utils/uuid_token';
const state = {
    detailInfo: {},
    uuid_token: getUUID()
}
const mutations = {
    RECEIVE_DETAILINFO(state, data) {
        state.detailInfo = data
    }
}
const actions = {
    async getDetailInfo({ commit }, skuId) {
        const data = await reqDetailInfo(skuId);
        if (data.code === 200) {
            commit('RECEIVE_DETAILINFO', data.data)

        }
    },
    async addOrUpdateShopCart({ commit }, { skuId, skuNum }) {
        let result = await reqAddOrUpdateShopCart(skuId, skuNum);
        if (result.code === 200) {
            return 'ok'
        } else {
            return Promise.reject(new Error('faile'))
        }
    }

}
const getters = {
    categoryView(state) {
        return state.detailInfo.categoryView || {}
    },
    skuInfo(state) {
        return state.detailInfo.skuInfo || {}
    },
    spuSaleAttrList(state) {
        return state.detailInfo.spuSaleAttrList || []
    }
}
export default {
    state,
    mutations,
    actions,
    getters
}
